Reputation:
Reputation:
I just use JavaScript with thread ID dynamically loaded into threads, if you want it just tell me
Reputation:
Reputation:
thread_view
template<script>
function lockThread() {
const phpScriptUrl = `auto_lock_thread.php?id={$thread.thread_id}`;
fetch(phpScriptUrl)
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok.');
}
return response.text();
})
.then(data => {
console.log('Thread Lock Response:', data);
const lockResult = document.getElementById('lock-result');
if (lockResult) {
lockResult.textContent = data;
}
})
.catch(error => {
console.error('There was an error locking the thread:', error);
});
}
window.onload = function() {
lockThread();
};
</script>
<?php
declare(strict_types=1);
$host = "ADD YOUR DETAILS";
$port = 3306;
$username = "ADD YOUR DETAILS";
$password = "ADD YOUR DETAILS";
$dbname = "ADD YOUR DETAILS";
$mysqli = new mysqli($host, $username, $password, $dbname, $port);
if ($mysqli->connect_error) {
die("<pre>Connection failed: " . $mysqli->connect_error . "</pre>");
}
$thread_id = isset($_GET['id']) ? (int)$_GET['id'] : 0;
if ($thread_id > 0) {
$sql = "
SELECT t.thread_id, t.user_id, t.title, t.discussion_open, u.username, u.message_count
FROM xf_thread t
INNER JOIN xf_user u ON t.user_id = u.user_id
WHERE t.thread_id = ?
";
$stmt = $mysqli->prepare($sql);
$stmt->bind_param('i', $thread_id);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
$row = $result->fetch_assoc();
$username = (string) $row['username'];
$title = (string) $row['title'];
$message_count = (int) $row['message_count'];
$discussion_open = (int) $row['discussion_open'];
if ($discussion_open === 1 && $message_count < 5) {
$lock_thread_sql = "UPDATE xf_thread SET discussion_open = 0 WHERE thread_id = ?";
$lock_stmt = $mysqli->prepare($lock_thread_sql);
$lock_stmt->bind_param('i', $thread_id);
if ($lock_stmt->execute()) {
echo "<pre>Thread titled '$title' by user '$username' has been locked because the creator's message count is less than 5.</pre>";
} else {
echo "<pre>Error locking thread '$title': " . $lock_stmt->error . "</pre>";
}
$lock_stmt->close();
} elseif ($discussion_open === 0) {
echo "<pre>Thread '$title' is already locked.</pre>";
} else {
echo "<pre>The thread creator's message count is 5 or more, thread '$title' will not be locked.</pre>";
}
} else {
echo "<pre>Thread with ID $thread_id not found.</pre>";
}
$stmt->close();
} else {
echo "<pre>Thread ID is missing or invalid.</pre>";
}
$mysqli->close();
?>
Reputation:
($discussion_open === 1 && $message_count < 5)